/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package TapestryModel.impl;

import TapestryModel.ContentObject;
import TapestryModel.ParamLink;
import TapestryModel.TapestryModelPackage;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Content Object</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link TapestryModel.impl.ContentObjectImpl#getLink <em>Link</em>}</li>
 *   <li>{@link TapestryModel.impl.ContentObjectImpl#getType <em>Type</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ContentObjectImpl extends ContentDataImpl implements ContentObject {

    @Override
    public boolean isReference() {
        return true;
    }

    @Override
    public String getTypeName() {
        return getType().getName();
    }

    /**
     * The cached value of the '{@link #getLink() <em>Link</em>}' containment reference.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getLink()
     * @generated
     * @ordered
     */
    protected ParamLink link;

    /**
     * The cached value of the '{@link #getType() <em>Type</em>}' reference.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getType()
     * @generated
     * @ordered
     */
    protected TapestryModel.Object type;

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    protected ContentObjectImpl() {
        super();
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    protected EClass eStaticClass() {
        return TapestryModelPackage.Literals.CONTENT_OBJECT;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public ParamLink getLink() {
        return link;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public NotificationChain basicSetLink(ParamLink newLink, NotificationChain msgs) {
        ParamLink oldLink = link;
        link = newLink;
        if (eNotificationRequired()) {
            ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, TapestryModelPackage.CONTENT_OBJECT__LINK, oldLink, newLink);
            if (msgs == null) msgs = notification; else msgs.add(notification);
        }
        return msgs;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setLink(ParamLink newLink) {
        if (newLink != link) {
            NotificationChain msgs = null;
            if (link != null)
                msgs = ((InternalEObject)link).eInverseRemove(this, TapestryModelPackage.PARAM_LINK__OWNER, ParamLink.class, msgs);
            if (newLink != null)
                msgs = ((InternalEObject)newLink).eInverseAdd(this, TapestryModelPackage.PARAM_LINK__OWNER, ParamLink.class, msgs);
            msgs = basicSetLink(newLink, msgs);
            if (msgs != null) msgs.dispatch();
        }
        else if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, TapestryModelPackage.CONTENT_OBJECT__LINK, newLink, newLink));
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public TapestryModel.Object getType() {
        if (type != null && type.eIsProxy()) {
            InternalEObject oldType = (InternalEObject)type;
            type = (TapestryModel.Object)eResolveProxy(oldType);
            if (type != oldType) {
                if (eNotificationRequired())
                    eNotify(new ENotificationImpl(this, Notification.RESOLVE, TapestryModelPackage.CONTENT_OBJECT__TYPE, oldType, type));
            }
        }
        return type;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public TapestryModel.Object basicGetType() {
        return type;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setType(TapestryModel.Object newType) {
        TapestryModel.Object oldType = type;
        type = newType;
        if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, TapestryModelPackage.CONTENT_OBJECT__TYPE, oldType, type));
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
        switch (featureID) {
            case TapestryModelPackage.CONTENT_OBJECT__LINK:
                if (link != null)
                    msgs = ((InternalEObject)link).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - TapestryModelPackage.CONTENT_OBJECT__LINK, null, msgs);
                return basicSetLink((ParamLink)otherEnd, msgs);
        }
        return super.eInverseAdd(otherEnd, featureID, msgs);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
        switch (featureID) {
            case TapestryModelPackage.CONTENT_OBJECT__LINK:
                return basicSetLink(null, msgs);
        }
        return super.eInverseRemove(otherEnd, featureID, msgs);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public Object eGet(int featureID, boolean resolve, boolean coreType) {
        switch (featureID) {
            case TapestryModelPackage.CONTENT_OBJECT__LINK:
                return getLink();
            case TapestryModelPackage.CONTENT_OBJECT__TYPE:
                if (resolve) return getType();
                return basicGetType();
        }
        return super.eGet(featureID, resolve, coreType);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public void eSet(int featureID, Object newValue) {
        switch (featureID) {
            case TapestryModelPackage.CONTENT_OBJECT__LINK:
                setLink((ParamLink)newValue);
                return;
            case TapestryModelPackage.CONTENT_OBJECT__TYPE:
                setType((TapestryModel.Object)newValue);
                return;
        }
        super.eSet(featureID, newValue);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public void eUnset(int featureID) {
        switch (featureID) {
            case TapestryModelPackage.CONTENT_OBJECT__LINK:
                setLink((ParamLink)null);
                return;
            case TapestryModelPackage.CONTENT_OBJECT__TYPE:
                setType((TapestryModel.Object)null);
                return;
        }
        super.eUnset(featureID);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public boolean eIsSet(int featureID) {
        switch (featureID) {
            case TapestryModelPackage.CONTENT_OBJECT__LINK:
                return link != null;
            case TapestryModelPackage.CONTENT_OBJECT__TYPE:
                return type != null;
        }
        return super.eIsSet(featureID);
    }

} //ContentObjectImpl
